<?php

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;

class areaModel extends Model
{

    protected $table = 'area';
    protected $primaryKey = 'id';

    /**
     * @param int $area_id
     * @param string $area_name
     * @return string
     */
    public static function getFullAreaName(int $area_id = 0, string &$area_name = ''): string
    {
        if($area_id){
            $area_arr = self::query()->where('id', $area_id)->first()->toArray();
            if(!empty($area_arr)){
                $area_name = $area_arr['name'].$area_name;
                if($area_arr['level'] > 1 && $area_arr['pid'] > 0){
                    self::getFullAreaName($area_arr['pid'], $area_name);
                }
            }
        }
        return $area_name;
    }

}
